import Vue from 'vue'
import Router from 'vue-router'
import store from '@/vuex/store'
import {constRouter, nonMenuRouter} from './routes'
import {localRouter} from './localRouter'

Vue.use(Router)

const routers = [
  ...constRouter,
  ...nonMenuRouter,
  ...localRouter
]
let router = new Router({
  base: '/',
  routes: routers
})
router.beforeEach((to, from, next) => {
  if (to.path) {
    store.commit('SET_CURRENT_ROUTE_PATH', to.path)
    let btnPermissions = to.meta && to.meta.btnPermissions
    if (btnPermissions && btnPermissions.length > 0) {
      sessionStorage.setItem('merchantBtnPermissions', JSON.stringify(btnPermissions))
    }
    next()
  } else {
    next()
  }
})

export default router
